<!--
 * @Author: Wangtao
 * @Date: 2021-04-01 11:41:07
 * @LastEditors: Wangtao
 * @LastEditTime: 2022-04-20 19:57:21
-->
<template>
  <div style="height: 100%">
    <commonSummary
      inputType="WEBCHAT"
      :randomNum="randomNum"
      :componentHeight="componentHeight"
      :propData="webchatData"
      moduleType="webchatData"
      :showListen="showListen"
      :isShowDrawer="isShowDrawer"
      :showDowload="showDowload"
      :visitorId="visitorId"
      @changeCustomerRelation="changeCustomerRelation"
    ></commonSummary>
  </div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import commonSummary from '@/components/commonSummary/index.vue'
import { WebchatModule } from '@/store/modules/webchat'
import { checkPermission } from '@/utils/directive'
@Component({
  name: 'webchatDataSummary',
  components: { commonSummary }
})
export default class WebchatDataSummary extends Vue {
  @Prop() private type: string | undefined
  @Prop() private isShowDrawer: boolean | undefined
  private $bus: any
  private $store: any
  private showDowload: boolean = false
  private showListen: boolean = false
  private componentHeight = 293
  private webchatData: any = {}
  private visitorId

  private randomNum = 0

  private mounted () {
    this.$bus.$on('initWebchatDataCenter', (res: any) => {
      this.visitorId = res.chatSession && res.chatSession.visitorId
      const actionData = { url: '/im-center/action/customer/locateCust', method: 'POST', data: { visitorId: res.chatSession.visitorId } }
      WebchatModule.webchatCommonAction(actionData).then(resp => {
        if (resp) {
          this.webchatData = {
            importType: 'webchatDataCenter', // 数据中心
            customerList: resp.data || {}, // 客户列表
            webchatDetails: res.chatSession, // 在线详情
            processInfo: res.processInfo, // 流程信息
            visitorInfo: res.visitorInfo || {} // 访客信息
          }
          this.randomNum = Math.random() + 1
        }
      })
    })
    if (checkPermission(null, { value: ['callSheet_audition'] })) { //  在线模块=》 联络记录的通话录音权限，按照数据中心的走
      this.showListen = true
      if (checkPermission(null, { value: ['callSheet_download'] })) {
        this.showDowload = true
      }
    }
  }

  private beforeMount () {
    if (checkPermission(null, { value: ['webchat_session_chat_tag'] })) {
      this.componentHeight = 293
    } else {
      this.componentHeight = 213
    }
  }

  private beforeDestroy () {
    this.$bus.$off('webchatVideoReplay')
    this.$bus.$off('initWebchatDataCenter')
  }

  private changeCustomerRelation (data: any) {
    data.type = this.type === 'session' ? 'dataCenterSession' : 'dataCenterLeave'
    WebchatModule.UPDATE_CUSTOMER_INFO(data)
  }
}
</script>
